package com.itheima.myscoket.test7;

import java.io.*;
import java.net.Socket;

public class ClinetDemo {
    public static void main(String[] args) throws IOException {
        //创建网络流(这一步是作为连接对象传到服务器的)
        Socket socket = new Socket("127.0.0.1",10000);
        //把本地文件读取到内存中,这是本地的流
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("day16_网络编程\\Client\\1.jpg"));
        //这是网络中的流,因为是输入到服务器所以用out
        OutputStream os = socket.getOutputStream();
        //将其包装缓冲流
        BufferedOutputStream bos = new BufferedOutputStream(os);
        //现在开始先读再写
        int b;
        while((b = bis.read())!=-1){
            //再写
            bos.write(b);
        }
        //在这体现为服务器结束读取
        socket.shutdownOutput();

        //服务器接收到信息后反馈给你文字,将网络长得流读
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        while ((line = br.readLine())!=null){
            System.out.println(line);
        }
        //关流
        br.close();
        //bos.close();
        os.close();
        bis.close();
        socket.close();
    }
}
